<?php

defined('BASEPATH') or die('forbidden');

class Track extends Model {

    function after_user_register($params = array()) {
        if ($params && isset($params['roleindex']) && $params['roleindex'] == 1) {
            $track_mac = $this->db->one("SELECT * FROM {pre}track_mac WHERE mac='{$params['mac']}'");
            if ($track_mac) {
                if ($track_mac['state'] == 0) {
                    $track_info = $this->db->one("SELECT * FROM {pre}track WHERE id='{$track_mac['trackId']}'");
                    if ($track_info && $track_info['state'] == 1) {
                        //更新状态
                        $this->db->update("{pre}track_mac", array('state' => 1, 'jointime' => time()), array('id' => $track_mac['id']));
                        //发送回调
                        if ($track_mac['trackId'] && $track_mac['mac']) {
                            $name = $track_mac['trackId'];
                            try {
                                if ($this->load->model("{$name}", null, "track/{$name}.php")) {
                                    call_user_func_array(array($this->$name, "sender"), array($track_info, $track_mac));
                                }
                            } catch (Exception $e) {
                                
                            }
                        }
                    }
                }
            }
        }
    }

}